case var expression when value < 0:
برای کد تبدیل نمره 0 تا 100 به گرید A تا F بصورت زیر است:
int mark = 70;
switch (mark)
{
case int n when n >= 90:
Console.WriteLine("Grade is A");
break;
case int n when n >= 80:
Console.WriteLine("Grade is B");
break;
case int n when n >= 70:
Console.WriteLine("Grade is C");
break;
case int n when n >= 60:
Console.WriteLine("Grade is D");
break;
case int n when n >= 50:
Console.WriteLine("Grade is E");
break;
default:
Console.WriteLine("Grade is F");
break;
}
switch (mark)
{
case int n when n >= 90:
Console.WriteLine("Grade is A");
break;
case int n when n >= 80:
Console.WriteLine("Grade is B");
break;
case int n when n >= 70:
Console.WriteLine("Grade is C");
break;
case int n when n >= 60:
Console.WriteLine("Grade is D");
break;
case int n when n >= 50:
Console.WriteLine("Grade is E");
break;
default:
Console.WriteLine("Grade is F");
break;
}